package com.ds.dsm.view.entity;

import com.ds.common.JDSException;
import com.ds.config.ResultModel;
import com.ds.dsm.view.config.action.CustomBuildAction;
import com.ds.dsm.view.config.service.FormConfigService;
import com.ds.esd.custom.annotation.CustomAnnotation;
import com.ds.esd.custom.annotation.FormViewAnnotation;
import com.ds.esd.custom.api.annotation.APIEventAnnotation;
import com.ds.esd.custom.form.enums.CustomFormMenu;
import com.ds.esd.custom.module.annotation.DynLoadAnnotation;
import com.ds.esd.custom.module.annotation.ModuleAnnotation;
import com.ds.esd.custom.nav.annotation.NavGroupAnnotation;
import com.ds.esd.custom.nav.annotation.NavTabsViewAnnotation;
import com.ds.esd.custom.toolbar.BottomBarMenu;
import com.ds.esd.dsm.DSMFactory;
import com.ds.esd.dsm.view.ViewEntityConfig;
import com.ds.esd.tool.ui.enums.Dock;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(path = "/dsm/view/config/entity/")
@BottomBarMenu(menuClass = CustomBuildAction.class)
@NavGroupAnnotation(
        bottombarMenu = {CustomFormMenu.Save, CustomFormMenu.ReSet}, customService = FormConfigService.class)
public class ViewInfoGroup {
    @CustomAnnotation(uid = true, hidden = true)
    private String esdclass;
    @CustomAnnotation(pid = true, hidden = true)
    private String viewInstId;
    @CustomAnnotation(pid = true, hidden = true)
    private String domainId;
    @CustomAnnotation(pid = true, hidden = true)
    private String methodName;


    public ViewInfoGroup() {
    }

    @RequestMapping(method = RequestMethod.POST, value = "ViewEntityBaseInfo")
    @FormViewAnnotation()
    @ModuleAnnotation(caption = "实体信息", dock = Dock.top, height = "150")
    @ResponseBody
    @APIEventAnnotation(autoRun = true)
    public ResultModel<ViewEntityFormView> getViewEntityBaseInfo(String sourceClassName, String domainId, String viewInstId) {
        ResultModel<ViewEntityFormView> result = new ResultModel<ViewEntityFormView>();
        try {
            ViewEntityConfig viewEntityConfig = DSMFactory.getInstance().getViewManager().getViewEntityConfig(sourceClassName, viewInstId);
            result.setData(new ViewEntityFormView(viewEntityConfig));
        } catch (JDSException e) {
            e.printStackTrace();
        }
        return result;
    }


    @RequestMapping(method = RequestMethod.POST, value = "ViewEntityMetaInfo")
    @DynLoadAnnotation
    @NavTabsViewAnnotation
    @ModuleAnnotation(dock = Dock.fill, caption = "关联信息", imageClass = "spafont spa-icon-c-databinder")
    @ResponseBody
    public ResultModel<ViewEntityInfoView> getViewEntityMetaInfo(String viewInstId, String domainId, String sourceClassName) {
        ResultModel<ViewEntityInfoView> result = new ResultModel<ViewEntityInfoView>();
        return result;

    }

    public String getDomainId() {
        return domainId;
    }

    public void setDomainId(String domainId) {
        this.domainId = domainId;
    }

    public String getMethodName() {
        return methodName;
    }

    public void setMethodName(String methodName) {
        this.methodName = methodName;
    }

    public String getEsdclass() {
        return esdclass;
    }

    public void setEsdclass(String esdclass) {
        this.esdclass = esdclass;
    }

    public String getViewInstId() {
        return viewInstId;
    }

    public void setViewInstId(String viewInstId) {
        this.viewInstId = viewInstId;
    }
}
